﻿using System;
using System.Web.UI;
using EmptyWallGallery.Core;
using Microsoft.VisualBasic;

namespace EmptyWallGallery.FrontEnd.inside.Editor.Products
{
    public partial class Album : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindData();
        }

        public void BindData()
        {
            RptListAlbum.DataSource = Core.BLL.Album.Instance.GetAll();
            RptListAlbum.DataBind();
        }

        protected void BtnCreateClick(object sender, EventArgs e)
        {
            if (txtAlbumName.Text.Length <= 1) return;

            Core.BLL.Album.Instance.Create(Core.Utilities.Common.Instance.NoHtml(txtAlbumName.Text),
                                           Core.Utilities.Common.Instance.NoHtml(txtDescription.Text), "");

            txtDescription.Text = "";
            txtAlbumName.Text = "";
            BindData();
        }

        protected string WriteAlbumImage(object eval)
        {
            var strImageDefault = eval.ToString() == "" ? "/images/no-image.jpg" : eval.ToString();
            return "<img src=\"" + strImageDefault + "\" border=\"0\" width=\"130\" height=\"100\" />";
        }

        protected string WriteCreateDate(string toString)
        {
            return Strings.Format(DateTime.Parse(toString).AddHours(Configs.TimeLine),
                                  "dd-MM-yyyy");
        }
    }
}